/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.component.schema;

import com.inspur.edp.caf.cef.schema.base.element.impl.DefaultOperation;
import com.inspur.edp.caf.cef.schema.datatype.DataType;
import com.inspur.edp.caf.cef.schema.element.Operation;
import com.inspur.edp.caf.cef.schema.element.Parameter;
import com.inspur.edp.component.schema.utils.DataTypeConverter;

import java.util.ArrayList;
import java.util.List;

/**
 * @auther zhouyjtr
 * @date 2021年12月31日
 */
public class GspCompOperation extends DefaultOperation implements Operation {

    private String id;

    //    public static final String KIND = "GspCompOperation";
    public static final String KING = DefaultOperation.KIND;

    public GspCompOperation() {
        this.setKind(KIND);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Override
    public GspCompParamType getReturnType() {
        return (GspCompParamType) super.getReturnType();
    }

    /**
     * 此方法cdt序列化会使用
     *
     * @param returnType 内部转化为GspCompParamType
     */
    @Override
    public void setReturnType(DataType returnType) {
        if (returnType == null || returnType instanceof GspCompParamType) {
            setReturnType((GspCompParamType) returnType);
        } else {
            GspCompParamType paramType = DataTypeConverter.getGspCompParamType(returnType);
            setReturnType(paramType);
        }
    }

    public void setReturnType(GspCompParamType returnType) {
        super.setReturnType(returnType);
    }

    @Override
    public final List<Parameter> getParameters() {
        return super.getParameters();
    }

    @Override
    public void setParameters(List<Parameter> parameters) {
        super.setParameters(parameters);
    }

    public List<? extends GspCompParameter> getCompParameters() {
        return (List<GspCompParameter>) ((Object) super.getParameters());
    }

    public void addParameter(GspCompParameter param) {
        List<Parameter> parametersList = getParameters();
        if (parametersList == null) {
            parametersList = new ArrayList<>();
            setParameters(parametersList);
        }
        parametersList.add(param);
    }

    @Override
    public String getKind() {
        return KIND;
    }

}
